#!/bin/bash
#
# Generate a free icons.c for minidlna from logo
#
# Copyright (C) 2011 Benoît Knecht <benoit.knecht@fsfe.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of the University nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# Usage: ./make_icons.sh ${omv_logo} > icons.c
#
#        where ${omv_logo} is the name of the logo you want to convert.
#
#        You'll need to have inkscape and imagemagick installed for this script
#        to work.

omv="${1}"
png="$(mktemp)"
jpg="$(mktemp)"

cat <<EOF
/* 
 *	OMV Logo
 */
EOF

inkscape -e "${png}" -h 48 "${omv}" > /dev/null
mogrify -gravity center -extent 48x48 -background none "${png}"
convert "${png}" -background black -flatten jpg:"${jpg}"
echo ''
echo '/* Small OMV PNG logo */'
echo 'unsigned char'
xxd -p -c 24 "${png}" | sed -e '    s/../\\x&/g' \
                            -e '1   s/^/png_sm\[\] =   "/' \
                            -e '1 ! s/^/             "/' \
                            -e '    s/$/"/' \
                            -e '$   s/$/;/'

inkscape -e "${png}" -h 120 "${omv}" > /dev/null
mogrify -gravity center -extent 120x120 -background none "${png}"
echo ''
echo '/* Large OMV PNG logo */'
echo 'unsigned char'
xxd -p -c 24 "${png}" | sed -e '    s/../\\x&/g' \
                            -e '1   s/^/png_lrg\[\] =  "/' \
                            -e '1 ! s/^/             "/' \
                            -e '    s/$/"/' \
                            -e '$   s/$/;/'

echo ''
echo '/* Small OMV JPEG logo */'
echo 'unsigned char'
xxd -p -c 24 "${jpg}" | sed -e '    s/../\\x&/g' \
                            -e '1   s/^/jpeg_sm\[\] =  "/' \
                            -e '1 ! s/^/             "/' \
                            -e '    s/$/"/' \
                            -e '$   s/$/;/'

convert "${png}" -background black -flatten jpg:"${jpg}"
echo ''
echo '/* Large OMV JPEG logo */'
echo 'unsigned char'
xxd -p -c 24 "${jpg}" | sed -e '    s/../\\x&/g' \
                            -e '1   s/^/jpeg_lrg\[\] = "/' \
                            -e '1 ! s/^/             "/' \
                            -e '    s/$/"/' \
                            -e '$   s/$/;/'

rm -f "${png}" "${jpg}"
